package com.java.huxb.threadlocal;

import com.java.huxb.utils.ThreadUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * @author huxb
 * @date 2020/4/9 0009 下午 4:09
 */
public class ThreadLocal002 {
    static SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd hh:mm:ss");
    public  String date(int seconds) {
        Date  date = new Date(1000 * seconds);
        String format = null;
        synchronized (ThreadLocal002.class) {
            format = dateFormat.format(date);
        }
        return format;
    }

    public static void main(String[] args) {
        Set<String> set = new HashSet<>(1000);
        for (int i = 1; i < 1000; i++) {
            int ii = i;
            ThreadUtils.execute(() -> {
                String date = new ThreadLocal002().date(ii);
                set.add(date);
                System.out.println(date);
                System.out.println(set.size());
            });
        }

    }
}
